Skip to main content

Leetcode 319

· One min read
Junhe Chen

This is a harder question for me, write on paper and find the parttern.

class Solution {
public int bulbSwitch(int n) {
// n == 0 all bulbs are off
// n == 1 all bulbs with factor of 1
// n == 2 all bulbs with factor 2 (2,4,6,8,10)...
// n == 3 all bulbs with factor 3 (3,6,9).....
// ......
// so we are finding number from 1 to n are perfect square
// essencially we are trying to find the sqrt of the n
return (int) Math.sqrt(n);
}
}